package com.zide.auth.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.zide.auth.domain.vo.request.LoginReqVO;
import com.zide.auth.service.MemberUserService;
import com.zide.auth.utils.satoken.StpMemberUtil;
import com.zide.common.core.domain.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author 石添
 * @date 2024/8/24
 */
@RestController
@RequestMapping("auth/member")
@Tag(name = "会员认证管理")
@RequiredArgsConstructor
public class MemberAuthController {

    private final MemberUserService memberUserService;

    @Operation(description = "登录")
    @PostMapping("login")
    public CommonResult login(@RequestBody LoginReqVO reqVO) {
        String token = memberUserService.login(reqVO);
        return CommonResult.success().put("token",token);
    }

    @SaCheckLogin(type = StpMemberUtil.TYPE)
    @Operation(description = "获取用户所有角色和权限信息")
    @GetMapping("permission")
    public CommonResult searchPermission() {
        String token = memberUserService.searchPermission();
        return CommonResult.success().put("token",token);
    }

    @Operation(description = "退出登录")
    @PostMapping("logout")
    public CommonResult logout() {
        memberUserService.logout();
        return CommonResult.success();
    }

}
